﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web;

namespace UrlRewriter
{
    public class Config
    {
        private IList<UrlConfig> _elements = new List<UrlConfig>();

        public IList<UrlConfig> Elements
        {
            get { return _elements; }
            set { _elements = value; }
        }

        private static Config _instance = new Config();

        public static Config Instance
        {
            get { return _instance; }
        }

        private Config()
        {
            GetConfigElements();
        }

        public void AddConfig(string fromUrl, string toUrl)
        {
            _elements.Add(new UrlConfig(fromUrl, toUrl));
        }

        public void GetConfigElements()
        {
            //默认（首）页
            AddConfig(@"^/Default.aspx$", @"/Pages/Index.aspx");
            //用户主页
            AddConfig(@"^/([^\/]+)$", @"/Pages/UserHome.aspx?username=$1");
            //首页
            AddConfig(@"^(/orderby/(?<orderby>[^\/]*))?(/category/(?<category>[^\/]*))?(/key/(?<key>[^\/]*))?$"
                , @"/Pages/Index.aspx?category=${category}&orderby=${orderby}&key=${key}");
            //个人信息编辑页
            AddConfig(@"^/profile/edit$", @"/Pages/UserBasicInfo.aspx");
            //消息页
            AddConfig(@"^/conversations/(all|fromme|tome)$", @"/Pages/MessageBox.aspx?type=$1");
            //服务收藏
            AddConfig(@"^/services/favorite$", @"/Pages/UserFavorite.aspx");
            //服务管理
            AddConfig(@"^/services/manage(?:/([^\/]+))?$", @"/Pages/ServiceManage.aspx?status=$1");
            //订单管理
            AddConfig(@"^/orders/seller$", @"/Pages/OrderList.aspx");
            AddConfig(@"^/orders/buyer$", @"/Pages/ShoppingList.aspx");

            //服务详细页
            AddConfig(@"^/service/(.+)$", @"/Pages/ServiceDetail.aspx?serviceTitle=$1");

        }
    }
}
